<!DOCTYPE>
<html>
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="__PUBLIC__/Home/css/user_center.css">
    <script src="__PUBLIC__/Admin/js/jquery-1.9.1.js"></script>
    <script src="__PUBLIC__/Common/Layer/layer.js"></script>

    <title>会员中心</title>
</head>

<body>
<!-- 栏目 -->
<include file="Public:header_center" />

<!-- 内容 -->
<style>
   /* #layui-layer1{
        top: 60px !important;
    }*/

    .layui-layer{
        top:100px !important;
    }

</style>
<style>
    .col_detail{
        width: 250px;
        height:260px;
        border: 1px solid #CCCCCC;
        margin: 10px 5px;
        float: left;
    }

    .col_detail ul {
        width: 240px;
        margin: 5px auto;
    }

    .title{
        color: #ff4001;
        font-weight: bold;
    }
    .text_content{
        width: 500px;
        border: 1px solid #CCCCCC;
        line-height: 28px;
    }
    td{
        font-size: 14px;
        line-height: 28px;
        height: 28px;
    }
    td button{
        border: none;
        background-color: #ff4001;
        width: 100px;
        height: 30px;
        border-radius: 5px;
        margin-left: 150px;
        font-size: 18px;
        color: #ffffff;
    }
    .page_bottom{
        margin-top: 30px;
    }
    .tr_head{
        background-color: #f2f2f2;
        text-align: center;
        height:50px;
    }
    .page_bottom tr{
        border-bottom: 1px solid #CCCCCC;
        text-align: center;
    }
    .tr_content a{
        color: #3366cc;
        display: inline-block;
        padding: 10px;
    }
    .tr_content a:hover{
        color: #ff4001;
    }




</style>
<div style="background-color:#f5f5f5;">
    <div class="content" style="width:1200px;">

        <include file="Public:left_center" />

        <div class="center-right right">
            <h3 class="title" style="color:#000;font-weight:400;">新增收货地址</h3>
            <div class="Options" style=" width:1050px; background-color:#FFF; padding:20px;">
                <table cellspacing="10" cellpadding="0" style="border: 1px solid #CCCCCC; width: 100%;">
                    <tr>
                        <td style=" width: 15%; text-align: right;">收货人：</td>
                        <td style=" width: 85%">
                            <input type="text" name="realname" id="realname" class="text_content" value="" />
                        </td>
                    </tr>
                    <tr>
                        <td style=" width: 15%; text-align: right;">所在地区：</td>
                        <script src="__PUBLIC__/Mobile/js/jquery.cityselect.js" type="text/javascript" style="border:0;"></script>
                        <td style=" width: 85%">
                            <div class="userAddItem"  id="userAddItem" style="color:#ABAEBB; height: 28px">
                                <select class="prov"  id="prov"   name="prov"  style="width:15%; border:1px solid #CCCCCC;font-size:1em; line-height: 25px; height: 25px;"></select>
                                <select class="city"  id="city"  name="city" disabled="disabled" style="width:15%; border:1px solid #CCCCCC; line-height: 25px; font-size:1em; height: 25px;"></select>
                                <select class="dist" id="dist"   name="dist" disabled="disabled" style="width:15%; border:1px solid #CCCCCC; line-height: 25px; font-size:1em; height: 25px;"></select>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td style=" width: 15%; text-align: right;">详细地址：</td>
                        <td style="width: 85%">
                            <input type="text" name="address" id="address" class="text_content"/>
                        </td>
                    </tr>
                    <tr>
                        <td style=" width: 15%; text-align: right;">手机号：</td>
                        <td style=" width: 85%">
                            <input type="text" name="mobile" id="mobile" class="text_content"  />
                        </td>
                    </tr>
                    <tr>

                        <td style=" width: 15%; text-align: right;">设为默认地址：</td>
                        <td style=" width: 85%">
                            <p style="padding-left: 10px;"><input type="checkbox" name="status" id="status" value="1" ></p>

                        </td>

                    </tr>
                    <tr>
                        <td colspan="2">
                            <button onclick="information_add({$user_id});" >保存</button>
                        </td>
                    </tr>
                </table>
                <div class="page_bottom">
                    <table  cellspacing="0" cellpadding="0" style="border: 1px solid #CCCCCC; width: 100%;">
                        <tr class="tr_head">
                            <td style="width: 15%">
                                收货人
                            </td>
                            <td style="width: 25%">
                                所在地区
                            </td>
                            <td style="width: 20%">
                                详细地址
                            </td>
                            <td style="width: 20%">
                                手机号
                            </td>
                            <td style="width: 20%">
                                操作
                            </td>
                        </tr>
                        <foreach name="list" item="vo">
                            <tr class="tr_content" id="tr_content{$vo.id}">
                                <td style="width: 15%">
                                    {$vo.realname}
                                </td>
                                <td style="width: 25%">
                                    {$vo.prov}{$vo.city}{$vo.dist}
                                </td>
                                <td style="width: 20%">
                                    {$vo.address}
                                </td>
                                <td style="width: 20%">
                                    {$vo.mobile}
                                </td>
                                <td style="width: 20%">
                                    <a href="javascript:void (0);" onclick="addr_edite({$vo.id})">编辑</a>|<a href="javascript:void (0);" onclick="addr_del({$vo.id})">删除</a>
                                </td>
                            </tr>
                        </foreach>
                    </table>
                </div>
            </div>


        </div>

    </div>
</div>
<!-- 底部 -->
<include file="Public:footer_center" />
<script>
    $(function(){
        $("#userAddItem").citySelect({
            url:"__PUBLIC__/Mobile/js/city.min.js",
            prov: "",//默认值  可写可不写
            city: "",
            dist: "",
            nodata: "none"
        });
    });
</script>
<script>
    function information_add(id){
        var realname = $('#realname').val();
        if(realname==''){
            layer.msg('收货人不能为空');
            return false;
        }
        var address = $('#address').val();
        if(address==''){
            layer.msg('详细地址不能为空');
            return false;
        }
        var mobile = $('#mobile').val();
        if(mobile==''){
            layer.msg('手机号不能为空');
            return false;
        }
        var reg = /^1[34578]\d{9}$/;
        if(!reg.test(mobile)){
            layer.msg('手机号填写不正确');
            return false;
        }
        var prov = $('#prov').val();
        var city = $('#city').val();
        var dist = $('#dist').val();
        if($('#status').is(':checked')){
            var status = 1;
        }else{
            var status=0;
        }
        $.ajax({
            type: "POST",
            url: "{:U('User/add_address')}",
            data: {user_id:id,realname:realname,address:address,mobile:mobile,prov:prov,city:city,dist:dist,status:status},
            dataType:'json',
            success: function(msg){
                if(msg==1){
                    // layer.msg('地址添加成功');
                    layer.msg('地址添加成功', {
                        time: 2000 //2秒关闭（如果不配置，默认是3秒）
                    }, function(){
                        parent.location.href="{:U('User/add_address')}";
                    });
                }else{
                    layer.msg('地址添加失败');
                }
            }
        });

    }
    //弹出编辑框
    function addr_edite(id){
        layer.open({
            type: 2,
            title: "更新收货地址",
            shadeClose: true,
            shade: 0.8,
            area: ['400px', '400px'],
            content: "{:U('User/addr_edite')}?id="+id //iframe的url
        });

    }

    //删除地址
    function addr_del(id){
        $.post("{:U('User/addr_del')}", { "id": id },
                function(data){
                    if(data==1){
                        layer.msg('删除成功',function(){
                            $('#tr_content'+id).remove();
                        });
                    }else{
                        layer.msg('删除失败');
                    }
       }, "json");
    }



</script>
</body>

</html>
